package com.xfp.mapper;

import com.github.pagehelper.Page;
import com.xfp.anntation.AutoFill;
import com.xfp.enumclass.OperationClass;
import com.xfp.pojo.dto.NodeDto;
import com.xfp.pojo.dto.newNodeDto;
import com.xfp.pojo.entity.Business;
import com.xfp.pojo.entity.Node;
import com.xfp.pojo.entity.Region;
import com.xfp.pojo.entity.Vm;
import com.xfp.pojo.vo.VmVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NodeMapper {

    /**
     * 区域详情--分页
     * @param dto
     * @return
     */
    Page<Node> pageNode(NodeDto dto);

    /**
     * 查询区域
     */
    @Select("select * from tb_region where id = #{id} ")
    Region findRegionById(String id);

    /**
     * 查询商圈
     */
    @Select("select * from tb_business where id = #{id}  ")
    Business findBusinessById(Integer id);

    /**
     * 查询商圈列表
     * @return
     */
    @Select("select * from tb_business")
    List<Business> findBusinessList();

    /**
     * 新增点位
     * @param dto
     * @return
     */
    @AutoFill(OperationClass.INSERT)
    @Insert("insert into tb_node (name,addr,area_code,create_user_id,region_id,business_id,owner_id,owner_name,update_time,create_time) values (#{name},#{addr},#{areaCode},#{createUserId},#{regionId},#{businessId},#{ownerId},#{ownerName},#{updateTime},#{createTime})")
    int insertNode(newNodeDto dto);

    /**
     * 修改点位
     * @param dto
     * @return
     */
    @AutoFill(OperationClass.UPDATE)
    int updateNode(newNodeDto dto);

    /**
     * 删除点位
     * @param nodeId
     */
    @Delete("delete from tb_node where id =#{nodeId}")
    void delete(String nodeId);

    /**
     * 根据id查询node
     * @param id
     * @return
     */
    @Select("select * from tb_node where id = #{id}")
    Node findById(String id);


    /**
     * 根据nodeid查询售货机
     * @param id
     * @return
     */
    @Select("select * from tb_vending_machine where node_id = #{id} ")
    List<Vm> findVmById(String id);

    /**
     * 查询区域里的售货机数量
     * @param nodeId
     * @return
     */
    @Select("select count(*) from tb_vending_machine where node_id = #{nodeId} ")
    int getVmCount(String nodeId);

}
